package com.starter.jienlee.config.advice;

import com.starter.jienlee.common.RestResult;
import com.starter.jienlee.common.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author jien.lee
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public RestResult businessException(BusinessException exception) {
        return RestResult.failed(exception.getCode(), exception.getMessage());
    }
}
